package controllers

import "CRMSystem/models"

type MainPageController struct {
	MainController
}

// GetViewInfo 获得主页展示信息
func (c *MainPageController) GetViewInfo() {
	c.IfHasSession()
	view, err := models.GetView()
	if err != nil {
		c.Data["json"] = Status{ErrCode: GET_ERR, Msg: "Error"}
		c.ServeJSON()
		c.StopRun()
	} else {
		c.Data["json"] = Status{Date: view, ErrCode: GET_OK, Msg: "GetViewInfo success"}
		c.ServeJSON()
		c.StopRun()
	}
}

// GetColumnViewInfo 获得图表信息
func (c *MainPageController) GetColumnViewInfo() {
	c.IfHasSession()
	view, err := models.GetCustomerCount()
	if err != nil {
		c.Data["json"] = Status{ErrCode: GET_ERR, Msg: "Error"}
		c.ServeJSON()
		c.StopRun()
	} else {
		c.Data["json"] = Status{Date: view, ErrCode: GET_OK, Msg: "GetViewInfo success"}
		c.ServeJSON()
		c.StopRun()
	}
}

// GetCycleViewInfo 获得饼图信息
func (c *MainPageController) GetCycleViewInfo() {
	c.IfHasSession()
	view, err := models.GetServiceInfo()
	if err != nil {
		c.Data["json"] = Status{ErrCode: GET_ERR, Msg: "Error"}
		c.ServeJSON()
		c.StopRun()
	} else {
		c.Data["json"] = Status{Date: view, ErrCode: GET_OK, Msg: "GetViewInfo success"}
		c.ServeJSON()
		c.StopRun()
	}
}
